import Enum from '@/vng/enum'
import LinkTypes from '../const/link-types'

const props = [
  {
    key: 'from',
    title: '始节点',
    type: Enum.Field.STRING,
    readOnly: true
  },
  {
    key: 'to',
    title: '末节点',
    type: Enum.Field.STRING,
    readOnly: true
  },
  {
    key: 'category',
    title: '分支形状',
    type: Enum.Field.STRING,
    args: {
      useList: true,
      options: LinkTypes
    }
  },
  {
    key: 'strokeWidth',
    title: '线宽',
    type: Enum.Field.FLOAT,
    args: {
      precision: 1
    }
  },
  {
    key: 'stroke',
    title: '颜色',
    type: Enum.Field.COLOR
  },
  {
    key: 'fontColor',
    title: '文字颜色',
    type: Enum.Field.COLOR
  },
  {
    key: 'fontSize',
    title: '文字大小',
    type: Enum.Field.INT
  }
  // {
  //   key: 'ortho',
  //   title: '正交',
  //   type: Enum.Field.BOOLEAN
  // }
]

function BuildItem(item, args) {
  const _item = { ...item }
  _item.data = args
  return _item
}

const factory = {
  from: function(item, datas, core) {
    const part = core.findNodeByKey(datas['from'])
    if (!part) {
      return BuildItem(item, undefined)
    } else {
      return BuildItem(item, part.data.text)
    }
  },
  to: function(item, datas, core) {
    const part = core.findNodeByKey(datas['to'])
    if (!part) {
      return BuildItem(item, undefined)
    } else {
      return BuildItem(item, part.data.text)
    }
  }
}

export default { props, factory }
